package com.ruoyi.live.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/live")
@CrossOrigin
public class LiveController {

    @PostMapping("/create")
    public AjaxResult create() {
        //String jwt =  "";
        //对 JWT 进行解析，获取用户名

        //根据用户名查出商户名称
        String sellerName = "huawei";

        //直播链接有效期 1 小时
        long currentTime = System.currentTimeMillis()/1000;
        long expireTime = currentTime + 3600;
        String txTime = Long.toHexString(expireTime);

        //txSecret = md5(key+StreamName+hex(time))
        String key = "d5f6bd173f84d5cbbf65fa373c6a827f";
        String txSecret = DigestUtils.md5Hex(key + sellerName +txTime).toLowerCase();

        Map map = new HashMap();
        map.put("txTime", txTime);
        map.put("txSecret", txSecret);
        map.put("streamName", sellerName);


        return AjaxResult.success(map);
    }
}
